<?php
namespace Mobile\Controller;

/**
 * Description of 我的客栈相关控制器接口
 * 
 * @modify wenhui 2016-11-10 创建
 * 
 */
class RoomSettingTypeController extends ParentController {

    private $hasRight = true;

	protected function _initialize() {
        parent::_initialize();
        $this->validateUtil = new \Org\Util\Validate();

        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            $this->hasRight = false;
        }
        $hotelId = $param['hotel'];
        $userId = $param['userId'];

        // 校验权限,目前只有超级管理员能访问
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $result = $adminAuthorityLogic->check($hotelId, $userId);
        if ($result == false) {
            $this->hasRight = false;
        }
        // 检查客栈是否已过期
        $hotelLogic = A('Common/Hotel', 'Logic');
        $result = $hotelLogic->checkHotelActive($hotelId);
        if ($result == false) {
            $this->hasRight = false;
        }
        $result = $hotelLogic->checkHotelStatus($hotelId);
        if ($result == false) {
            $this->hasRight = false;
        }
    }

    /**
     * 获取我的房型信息
     * @modify wenhui 2016-11-10    创建
     */
    public function roomType() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );
        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];

        //检验token
        $this->checkMobileToken($userId, $token);
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId); 
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $roomTypeInfo = $roomTypeBookLogic->getInfo($hotelId);

        // 处理数据
        foreach ($roomTypeInfo as &$roomTypeInfoItem) {
            unset($roomTypeInfoItem['isdelete']);
            unset($roomTypeInfoItem['hotelentity_id']);
            $roomTypeInfoItem['coverImageUrl'] = isset($roomTypeInfoItem['onlineData']['coverimageurl']) ? $roomTypeInfoItem['onlineData']['coverimageurl'] : '';
            $roomTypeInfoItem['description'] = isset($roomTypeInfoItem['onlineData']['description']) ? $roomTypeInfoItem['onlineData']['description'] : '';
            $roomTypeInfoItem['price'] = isset($roomTypeInfoItem['onlineData']['price']) ? $roomTypeInfoItem['onlineData']['price'] : 0.00;
            //$roomTypeInfoItem['picture'] = isset($roomTypeInfoItem['onlineData']['picture']) ? array_column($roomTypeInfoItem['onlineData']['picture'], 'name') : array();

            // 组装图片数组
            $roomTypeInfoItem['images'] = array();
            // 处理封面图片
            if (isset($roomTypeInfoItem['coverImageUrl'])) {
                if (!empty($roomTypeInfoItem['coverImageUrl'])) {
                    $images = array(
                        'imageUrl' => MEIZHU_URL . $roomTypeInfoItem['coverImageUrl'],
                        'isCover' => ENABLE,
                    );
                    array_push($roomTypeInfoItem['images'], $images);
                }
            }
            unset($roomTypeInfoItem['coverImageUrl']);

            // 处理房型图册图片
            foreach ($roomTypeInfoItem['onlineData']['picture'] as $imageItem) {
                if (!empty($imageItem['name'])) {
                    $images = array(
                        'imageUrl' => MEIZHU_URL . $imageItem['name'],
                        'imageId' => $imageItem['id'],
                        'isCover' => DISABLE,
                    );
                    array_push($roomTypeInfoItem['images'], $images);
                }
            }
            unset($imageItem);

            unset($roomTypeInfoItem['onlineData']);
        }
        unset($roomTypeInfoItem);

        $hotelPayLogic = A('Common/HotelPay', 'Logic');
        $result = $hotelPayLogic->getPayDetail($hotelId);
        // 获取酒店预定模式
        $hotelBookDetail = $hotelBookLogic->getInfo($hotelId, true);

        $data = array();
        // 组装数据
        $data['info'] = $roomTypeInfo;
        $data['deposit'] = isset($result['deposit']) ? $result['deposit'] : 0.00;
        $data['refundrule'] = isset($result['refundrule']) ? $result['refundrule'] : '';
        $data['bookMode'] = isset($hotelBookDetail['bookmode']) ? $hotelBookDetail['bookmode'] : 0;
   
        returnJson(200, 200, $data);
    }

    /**
     * 上架房型
     * @modify wenhui 2016-11-10    创建
     */
    public function enableRoomType() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
            'roomType' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];
        //检验token
        $this->checkMobileToken($userId, $token);

        // 校验客栈是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        try {
            $hotelBookLogic->checkCanEnableRoomType($hotelId);
        } catch (\Exception $e) {
            returnJson($e->getMessage());
            return;
        }

        // 校验是否可操作
        $roomTypeId = explode(',', $param['roomType']);
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }
        // 检查是否有房间权限操作房型
        if (!$roomTypeLogic->checkHasRight($hotelId, $roomTypeId)) {
            returnJson(403, 202);
            return;
        }

        // 校验是否可启用(至少需设置封面和设置价格)
        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $roomTypeDetail = $roomTypeBookLogic->getInfo($hotelId);
        $roomTypeDetail = getArrayValueAsIndex($roomTypeDetail, 'id');
        foreach ($roomTypeId as $roomTypeIdItem) {
            $roomTypeDetailItem = $roomTypeDetail[$roomTypeIdItem];
            if (empty($roomTypeDetail) || (empty($roomTypeDetailItem['onlineData']['coverimageurl']))) {
                returnJson(403, 305);
                return;
            }
        }
        unset($roomTypeIdItem);

        $enableResult = $roomTypeBookLogic->enableRoomType($hotelId, $roomTypeId);
        if (empty($enableResult)) {
            return;
        }
        returnJson(200, 200);
    }


    /**
     * 下架房间
     * @modify wenhui 2016-11-10    创建
     */
    public function disableRoomType() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
            'roomType' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];
        //检验token
        $this->checkMobileToken($userId, $token);

        // 校验客栈是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeId = explode(',', $param['roomType']);
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        // 检查是否有房间权限操作房型
        if (!$roomTypeLogic->checkHasRight($hotelId, $roomTypeId)) {
            returnJson(403, 202);
            return;
        }

        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $enableResult = $roomTypeBookLogic->diableRoomType($hotelId, $roomTypeId);
        if (empty($enableResult)) {
            return;
        }
        returnJson(200, 200);
    }

    /**
     * 控制房态开关
     * 切换我的客栈预定模式:预定到房型/预定到房间
     * @modify wenhui 2016-11-10    创建
     */
    public function toggleBookMode() {
        if (!$this->hasRight) {
            return;
        }
        
        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
            'bookMode' => 'notnull,notempty,booleanInt',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $userId = $param['userId'];
        $token = $param['token'];
        $hotelId = $param['hotel'];
        //检验token
        $this->checkMobileToken($userId, $token);

        // 校验客栈是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 修改信息
        $bookMode = $param['bookMode'];
        $hotelDetailModel = D('HotelDetail');
        $toggleResult = $hotelDetailModel->saveInfo($hotelId, null, null, null, null, null, null, null, null, null, null, null, null, null, $bookMode);
        if (empty($toggleResult)) {
            returnJson(500, 506);
            return;
        }

        returnJson(200, 200);
    }

    /**
     * 保存我的客栈房型特色的描述信息
     * @modify wenhui 2016-11-11    创建
     */
    public function saveRoomTypeDescription() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $hotelId = $param['hotel'];
        // 转换数据格式
        $room = json_decode(stripslashes(htmlspecialchars_decode($param['room'])),true);
        if (is_array($room)) {
            $version = getVersion(C('MOBILE_VERSION'));
            $validateRule = array(
                    'roomType' => 'notnull,notempty,id',
            );

            if ($version >= '2.0.06') {
                $validateRule['description'] = 'notnull,nameLength100';
            } else {
                $validateRule['description'] = 'notnull,nameLength50';
            }

            foreach ($room as $roomItem) {
                $validatePass = $this->ajaxValidateReturn($this->validateUtil, $roomItem, $validateRule);
                if (empty($validatePass)) {
                    return;
                }

                // 校验是否可操作
                $roomTypeId = explode(',', $roomItem['roomType']);
                $roomTypeLogic = A('Common/RoomType', 'Logic');
                $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
                if (empty($canEnable)) {
                    returnJson(403, 202);
                    return;
                }
            }
            unset($roomItem);
        }

        $userId = $param['userId'];
        $token = $param['token'];
        //检验token
        $this->checkMobileToken($userId, $token);

        // 校验客栈是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $SaveHotelLogic = A('Common/SaveHotel', 'Logic');
        $saveResult = $SaveHotelLogic->saveInfo($hotelId,$room);
        if (empty($saveResult)) {
            return;
        }
        returnJson(200, 200);
    }

    /**
     * 保存我的客栈房型价格与押金
     * @modify wenhui 2016-11-14    创建
     */
    public function saveRoomTypePrice() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
            'deposit' => 'notnull,notempty,decimal8_2',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $version = getVersion(array('2.0.16'));
        $hotelId = $param['hotel'];
        $deposit = $param['deposit'];
        // 转换数据格式
        $room = json_decode(stripslashes(htmlspecialchars_decode($param['room'])),true);
        if (is_array($room)) {
            foreach ($room as $roomItem) {
                $validateRule = array(
                    'roomType' => 'notnull,notempty,id',
                    'price' => 'notnull,notempty,decimal8_2',
                );
                $validatePass = $this->ajaxValidateReturn($this->validateUtil, $roomItem, $validateRule);
                if (empty($validatePass)) {
                    return;
                }

                // 校验是否可操作
                $roomTypeId = explode(',', $roomItem['roomType']);
                $roomTypeLogic = A('Common/RoomType', 'Logic');
                $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
                if (empty($canEnable)) {
                    returnJson(403, 202);
                    return;
                }

                //价格不能小于义卖价
                $roomTypeModel = D('RoomType');
                $roomTypeInfo = $roomTypeModel->getInfo($roomTypeId);
                if ($roomTypeInfo['charityprice'] != 0 && $roomItem['price'] <= $roomTypeInfo['charityprice']) {
                    returnJson(403, 426);
                }
            }
            unset($roomItem);
        }

        $userId = $param['userId'];
        $token = $param['token'];
        //检验token
        $this->checkMobileToken($userId, $token);

        // 校验客栈是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $SaveHotelLogic = A('Common/SaveHotel', 'Logic');
        $saveResult = $SaveHotelLogic->saveInfo($hotelId, $room, $deposit);
        if (empty($saveResult)) {
            return;
        }
        returnJson(200, 200);
    }

    /**
     * 保存退订规则
     * @modify wenhui 2016-11-14 创建
     *
     */
    public function saveRefundRule() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'rule' => 'notnull,notempty,nameLength255',
        );
        $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);

        $hotelId = $param['hotel'];
        // 检查操作权限
        $adminAuthorityLogic = A('Common/AdminAuthority', 'Logic');
        $adminAuthorityLogic->check($hotelId);

        $userId = $param['userId'];
        $token = $param['token'];
        //检验token
        $this->checkMobileToken($userId, $token);

        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        $refundRule = $param['rule'];
        $hotelPayLogic = A('Common/HotelPay', 'Logic');
        $hotelPayLogic->savePayRefundRule($hotelId, $refundRule);

        returnJson(200, 200);
    }

    /**
     * 保存房间图册图片
     * @modify wenhui 2016-11-14    创建
     */
    public function saveRoomTypeImage() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
            'roomType' => 'notnull,notempty,id',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $hotelId = $param['hotel'];
        $userId = $param['userId'];
        $token = $param['token'];
        $roomTypeId = $param['roomType'];

        //检验token
        $this->checkMobileToken($userId, $token);
        // 校验客栈是否已经开通
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $RoomTypeInfos = $roomTypeBookLogic->getInfoByRoomType($roomTypeId);

        $url = array();
        foreach ($RoomTypeInfos as $key => $RoomTypeItem) {
            if (!empty($RoomTypeItem['name'])) {
                array_push($url, $RoomTypeItem['name']);
            }
        }
        unset($RoomTypeItem);

        if (!isset($_FILES['file'])) {
            returnJson(500, 511);
        }
        // 调用上传图片函数 上传成功返回url 失败返回null
        $newUrl = mobileUpload($_FILES['file'], 'bookRoomType');
        array_push($url, $newUrl);

        // 描述图最多4张
        if (count($url) > 4) {
            returnJson(403, 414);
            return;
        }

        $saveResult = $roomTypeBookLogic->saveInfo($hotelId, $roomTypeId, null, null, null, $url);
        if (empty($saveResult)) {
            return;
        }

        if (!isset($newUrl)) {
            returnJson(500, 511);
        }

        // 获取新上传的图片Id
        $imageInfo = $roomTypeBookLogic->getImageInfo($roomTypeId, $newUrl);
        if ($imageInfo === false) {
            returnJson(500, 511);
        }
        $imageId = isset($imageInfo['id']) ? $imageInfo['id'] : '';

        $newUrl = MEIZHU_URL . $newUrl;
        returnJson(200, 200, array('imageUrl' => $newUrl, 'imageId' => $imageId));
    }

    /**
     * 保存房间封面图片信息
     * @modify wenhui 2016-11-15    创建
     */
    public function saveRoomTypeCover() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'hotel' => 'notnull,notempty,id',
            'imageId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'roomType' => 'notnull,notempty,id',
            'url' => 'notnull,notempty,nameLength255',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $userId = $param['userId'];
        $token = $param['token'];
        //检验token
        $this->checkMobileToken($userId, $token);

        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeId = explode(',', $param['roomType']);
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        // 先根据房型图片的id 删除房型图片
        $roomTypePictureId = isset($param['imageId']) ? $param['imageId'] : null;
        $saveResult = $roomTypeBookLogic->deleteRoomTypeImage($roomTypePictureId);
        if (empty($saveResult)) {
            return;
        }

        // 在修改封面之前 再拿出原来封面的url 保存到房型图册中
        $roomTypeId = $param['roomType'];
        $roomTypeInfo = $roomTypeBookLogic->getInfo($hotelId);
        foreach ($roomTypeInfo as $roomTypeInfoItem) {
            if ($roomTypeInfoItem['id'] == $roomTypeId) {
                $oldCoverUrl = isset($roomTypeInfoItem['onlineData']['coverimageurl']) ? $roomTypeInfoItem['onlineData']['coverimageurl'] : '';
            }
        }
        unset($roomTypeInfoItem);

        if (!empty($oldCoverUrl)) {
            // 拿原来房型图册图片 组装$url
            $RoomTypeInfos = $roomTypeBookLogic->getInfoByRoomType($roomTypeId);
            $urls = array();
            foreach ($RoomTypeInfos as $key => $RoomTypeItem) {
                array_push($urls, $RoomTypeItem['name']);
            }
            unset($RoomTypeItem);

            // 保存到房型图册中
            array_push($urls, $oldCoverUrl);

            // 描述图最多4张
            if (count($urls) > 4) {
                returnJson(403, 414);
                return;
            }

            $saveResult = $roomTypeBookLogic->saveInfo($hotelId, $roomTypeId, null, null, null, $urls);
            if (empty($saveResult)) {
                return;
            }

            // 获取新插入房型图片的图片Id
            $imageInfo = $roomTypeBookLogic->getImageInfo($roomTypeId, $oldCoverUrl);
            if ($imageInfo === false) {
                returnJson(500, 511);
            }

            $imageId = isset($imageInfo['id']) ? $imageInfo['id'] : '';
            if (!empty($imageId)) {
                $data = array(
                    'imageId' => $imageId,
                    'imageUrl' => MEIZHU_URL . $imageInfo['name'],
                );
            }
        }

        // 修改封面图片
        $url = parse_url($param['url'])['path'];
        $saveResult = $roomTypeBookLogic->saveInfo($hotelId, $roomTypeId, null, null, $url, null);
        if (empty($saveResult)) {
            return;
        }

        $data['coverUrl'] = MEIZHU_URL . $url;

        returnJson(200, 200, $data);
    }

    /**
     * 删除房间图片
     * @modify wenhui 2016-11-19    创建
     */
    public function deleteRoomTypeImage() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'roomType' => 'notnull,notempty,id',
            'isCover' => 'notnull,notempty',
            'hotel' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }
        $userId = $param['userId'];
        $token = $param['token'];
        //检验token
        $this->checkMobileToken($userId, $token);

        // 校验客栈是否已经开通
        $hotelId = $param['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            returnJson(403, 409);
            return;
        }

        // 校验是否可操作
        $roomTypeId = explode(',', $param['roomType']);
        $roomTypeLogic = A('Common/RoomType', 'Logic');
        $canEnable = $roomTypeLogic->checkExist($hotelId, $roomTypeId);
        if (empty($canEnable)) {
            returnJson(403, 202);
            return;
        }

        $roomTypePictureId = isset($param['imageId']) ? $param['imageId'] : null;
        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        // 判断删除的是否是封面 1：为封面
        if ($param['isCover'] == 1) {
            $roomTypeId = $param['roomType'];
            $saveResult = $roomTypeBookLogic->saveInfo($hotelId, $roomTypeId, null, null, '', null);
            if (empty($saveResult)) {
                return;
            }
        } else {
            $saveResult = $roomTypeBookLogic->deleteRoomTypeImage($roomTypePictureId);
            if (empty($saveResult)) {
                return;
            }
        }

        returnJson(200, 200);
    }

    /**
     * 获取地址经纬度信息
     * @modify trainyao 2016-04-28    创建
     */
    public function geoInfo() {
        if (!$this->hasRight) {
            return;
        }

        $param = I('post.');
        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
            'userId' => 'notnull,notempty,id',
            'token' => 'notnull,notempty',
            'address' => 'notnull,notempty,nameLength50',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (!$validatePass) {
            return;
        }

        $userId = $param['userId'];
        $token = $param['token'];
        //检验token
        $this->checkMobileToken($userId, $token);

        // 调用百度Api,获取经纬度
        $address = $param['address'];
        $opts = array(
            'http' => array(
                'method' => "GET",
                'timeout' => 10,
            ));
        $context = stream_context_create($opts);
        $url = "http://api.map.baidu.com/geocoder?address=" . urlencode($address) . "&output=json&key=37492c0ee6f924cb5e934fa08c6b1676&";
        $baiduData = file_get_contents($url, false, $context);
        $baiduData = iconv("GB2312", "UTF-8//IGNORE", $baiduData);
        $baiduData = json_decode($baiduData, true);

        if (isset($baiduData['result']) && isset($baiduData['result']['location']) && isset($baiduData['result']['location']['lng']) && isset($baiduData['result']['location']['lat'])) {
            returnJson(200, 200, array(
                'longtitude' => number_format($baiduData['result']['location']['lng'], 6, '.', ''),
                'latitude' => number_format($baiduData['result']['location']['lat'], 6, '.', ''),
            ));
            return;
        } else {
            returnJson(403, 600);
            return;
        }
    }
}